<?xml version="1.0" encoding="utf-8"?>
<!--
   This file is a part of dcstore project,
   licensed under GPLv2
  
   Dominik Cebula
   dominikcebula@gmail.com
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <ui:composition template="admin-template.xhtml">
            <ui:define name="main">                                       
                <table id="tbl_category" class="actions">
                    <thead>
                        <tr>
                            <th class="col1">id</th>
                            <th class="col2">name</th>
                            <th class="col3">actions</th>
                        </tr>
                    </thead>
                    <tbody>                            
                        <c:forEach items="#{categoryWeb.getAll()}" var="category">
                            <tr>
                                <td class="col1">#{category.id}</td>
                                <c:choose>
                                    <c:when test="#{request.getParameter('id') == category.id}">
                                        <h:form>
                                            <td class="col2">
                                                #{categoryWeb.setId(category.id)}
                                                #{categoryWeb.setName(category.name)}
                                                <h:inputHidden value="#{categoryWeb.id}" />
                                                <h:inputText validatorMessage="Wrong data in category field" required="true" requiredMessage="Category name is required" value="#{categoryWeb.name}" />
                                            </td>
                                            <td class="col3">
                                                <h:commandLink action="#{categoryWeb.edit()}" value="Save">
                                                    <f:param name="id" value="#{category.id}" />
                                                </h:commandLink>
                                            </td>
                                        </h:form>
                                    </c:when>
                                    <c:otherwise>
                                        <td class="col2">#{category.name}</td>
                                        <td class="col3">
                                            <h:form>
                                                <h:link value="Edit">
                                                    <f:param name="id" value="#{category.id}" />
                                                </h:link>&nbsp;
                                                <h:commandLink onclick="return confirm('Are you sure you want to delete this category?')" action="#{categoryWeb.del(category.id)}" value="Delete" />
                                            </h:form>
                                        </td>
                                    </c:otherwise>
                                </c:choose>
                            </tr>
                        </c:forEach>
                        <tr>
                            <h:form>
                                <td></td>
                                <td><h:inputText validatorMessage="Wrong data in category field" required="true" requiredMessage="Category name is required" value="#{categoryWeb.nameNew}" /></td>
                                <td><h:commandLink action="#{categoryWeb.add()}" value="Add" /></td>
                            </h:form>
                        </tr>
                    </tbody>
                </table>
            </ui:define>
        </ui:composition>
    </h:body>
</html>